/** CS2340 Spring 2011 Project
 *  Team: 40 Jiggawatt Hard Driver
 *  Suk Hwan Hong
 *  Rhys Saraceni
 *  Travis Cooper
 *  Luke Stubb
 *
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0 
 */

package edu.gatech.jiggawatt.office.model;

import java.io.Serializable;

/**
 * Represents calendar (schedule) of office
 * Contains all the appointments
 * @author 40 Jiggawatt Hard Driver
 * @version 1.0
 *
 */
public class OfficeCalendar implements Serializable
{
	int base = 2010; //calendar start from 2010 // $codepro.audit.disable numericLiterals
	int maxYear;
	YearlySchedule[] years;
	
	/**
	 * Creates office calendar for 100 years
	 */
	public OfficeCalendar()
	{
		years = new YearlySchedule[100]; // $codepro.audit.disable numericLiterals
		
		for (int i = 0; i < 100; i++) // $codepro.audit.disable numericLiterals
		{
			years[i] = new YearlySchedule(i + base);
		}
		
		maxYear = base + 99; // $codepro.audit.disable numericLiterals
	}
	
	/**
	 * Creates office calendar that spans n years
	 * @param n n years to span
	 */
	public OfficeCalendar(int n)
	{
		years = new YearlySchedule[n];
		
		for (int i = 0; i < n; i++)
		{
			years[i] = new YearlySchedule(i + base);
		}		
		
		maxYear = base + n - 1;
	}
	
	/**
	 * gets daily schedule
	 * @param date
	 * @return daily schedule
	 */
	public DailySchedule getDailySchedule(Date date)
	{
		int year = date.getYear();
		int month = date.getMonth();
		int day = date.getDay();
		
		return years[year - base].getMonthlySchedule(month).getDailySchedule(day);
	}
	
	/**
	 * gets list of yearly schedules
	 * @return list of yearly schedules
	 */
	public YearlySchedule[] getYearlySchedules()
	{
		return years;
	}
	
	/**
	 * adds appointment
	 * @param app
	 * @return true if success, false otherwise
	 */
	public boolean addAppointment(Appointment app) // $codepro.audit.disable booleanMethodNamingConvention
	{
		return getDailySchedule(app.getDate()).addAppointment(app);
	}
	
	/**
	 * removes appointment
	 * @param date
	 * @param time
	 * @return appointment removed
	 */
	public Appointment removeAppointment(Date date, Time time)
	{
		return getDailySchedule(date).removeAppointment(time);
	}
	
	/**
	 * changes appointment
	 * @param oldApp
	 * @param newApp
	 * @return true if success, false otherwise
	 */
	public boolean changeAppointment(Appointment oldApp, Appointment newApp) // $codepro.audit.disable booleanMethodNamingConvention
	{
		return getDailySchedule(oldApp.getDate()).changeAppointment(oldApp, newApp);
	}	
	
	/**
	 * gets appointment
	 * @param date
	 * @param time
	 * @return appointment retrieved
	 */
	public Appointment getAppointment(Date date, Time time)
	{
		return getDailySchedule(date).getAppointment(time);
	}
	
	/**
	 * gets base year
	 * @return base year
	 */
	public int getBaseYear()
	{
		return base;
	}
	
	/**
	 * gets max year
	 * @return max year
	 */
	public int getMaxYear()
	{
		return maxYear;
	}
	
	/**
	 * returns string representation of calendar
	 * @return string representation of calendar
	 */
	public String toString()
	{
		return "Calendar with base year:" + base + " max year: " + maxYear; // $codepro.audit.disable stringLiterals
	}
}